import 'package:app_admin/res/styles.dart';
import 'package:app_admin/routes/app_navigator.dart';
import 'package:app_admin/utils/utils.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:get/get.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart'
    as pk;

class OrderPlanAddLogic extends GetxController {
  final time = "请选择日期".obs;
  final startName = "".obs;
  final workName = "".obs;
  final endName = "".obs;
  final car = "".obs;

  @override
  void onReady() {
    super.onReady();
  }

  ///保存
  void btnSave(BuildContext context) {}

  ///计划日期
  void openDatePicker() {
    var appLocale = Get.locale;
    var isZh = appLocale!.languageCode.toLowerCase().contains("zh");
    pk.DatePicker.showDatePicker(Get.context!,
        locale: isZh ? LocaleType.zh : LocaleType.en,
        maxTime: DateTime.now(),
        theme: pk.DatePickerTheme(
          cancelStyle: Styles.ts_0C1C33_17sp,
          doneStyle: Styles.ts_0089FF_17sp,
          itemStyle: Styles.ts_0C1C33_17sp,
        ),
        onConfirm: updateTime);
  }

  void updateTime(DateTime dateTime) {
    var t = dateTime.millisecondsSinceEpoch;
    time.value = DateUtil.formatDateMs(
      t ?? 0,
      format: IMUtils.getTimeFormat1(),
    );
  }

  ///出矿采集场
  void openStartNameSelect(BuildContext context) {
    Pickers.showSinglePicker(context,
        data: ['阿斯顿', '地方', '士大夫'],
        selectData: startName.value,
        onConfirm: openStartNameOk);
  }

  void openStartNameOk(p, index) {
    startName.value = p;
  }

  ///工作面
  void openworkNameSelect(BuildContext context) {
    Pickers.showSinglePicker(context,
        data: ['阿斯顿', '地方', '士大夫'],
        selectData: workName.value,
        onConfirm: openworkNameOk);
  }

  void openworkNameOk(p, index) {
    workName.value = p;
  }

  ///卸矿点
  void openendNameSelect(BuildContext context) {
    Pickers.showSinglePicker(context,
        data: ['阿斯顿', '地方', '士大夫'],
        selectData: endName.value,
        onConfirm: openendNameOk);
  }

  void openendNameOk(p, index) {
    endName.value = p;
  }

  ///挖掘机
  void opencarSelect(BuildContext context) async {
    final result = await AppNavigator.startSelect(car.value);
    if (null != result) {
      car.value = result;
    }
  }
}
